<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>个人中心修改密码页面</title>
    <script src="../../../../res/js/jquery-3.4.1.min.js"></script>
    <script src="../../../../res/layui/layui.js" charset="utf-8"></script>
    <script src="../../../../res/js/Tools.js"></script>
    <link rel="stylesheet" href="../../../../res/layui/css/layui.css" media="all">
    <link href="../../../../res/echarts/eleTree.css" rel="stylesheet"/>
    <script src="../../../../res/echarts/eleTree.js"></script>
    <script src="../../../../res/js/login_common.js" charset="utf-8"></script>
    <style type="text/css">
        body {
            padding: 10px;
        }
    </style>
    <script>
        $.ajaxSetup({
            async: false
        });
        $(function(){
            var url=getRootPath()+"OaPersonnelAction/getUser";
            var data=getAjaxById(url);
            if(!data){
                window.location.href= getRootPath() + "pages/dkmoa/login.html";
            }else{
                $("#userId").val(data.pkPersonnelId);
            }
        })
    </script>
</head>
<body>
<form class="layui-form" id="formDId" action="" method="post" enctype="multipart/form-data">
    <input type="hidden" id="userId" name="userId">
    <div class="layui-form-item">
        <label class="layui-form-label">新密码</label>
        <div class="layui-input-inline">
            <input type="password" name="personnelPwd" id="personnelPwd" lay-verify="required"
                   autocomplete="off"  maxlength="50" placeholder="请输入新密码" class="layui-input">
        </div>
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-inline">
            <input type="password" name="personnelPwdTwo" id="personnelPwdTwo" lay-verify="required"
                   autocomplete="off"  maxlength="50" placeholder="请输入确定新密码" class="layui-input">
        </div>
    </div>

    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn site-demo-active" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary layui-bg-red">重置按钮</button>
        </div>
    </div>
</form>
<script>
    var form=null;
    layui.use(['form', 'layedit', 'laydate', 'layer'], function () {
        form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        //监听提交
        form.on('submit(demo1)', function (data) {
          var personnelPwd=$("#personnelPwd").val();
          var personnelPwdTwo=$("#personnelPwdTwo").val();
            if(personnelPwd.length<6){
                layer.msg("新密码长度不能低于六位,请重新输入");
                return false;
            }
            if(personnelPwdTwo.length<6){
                layer.msg("确认密码长度不能低于六位,请重新输入");
                return false;
            }
         if(data.field.personnelPwd!=data.field.personnelPwdTwo){
             layer.msg("密码不一致,请重新输入");
             return false;
         }else{
               // 单击之后提交按钮不可选,防止重复提交
                var DISABLED = 'layui-btn-disabled';
                // 增加样式
                $('.site-demo-active').addClass(DISABLED);
                // 增加属性
                $('.site-demo-active').attr('disabled', 'disabled');
                var url=getRootPath() + "/OaPersonnelAction/addOrUpdate";
                var dataJson={personnelPwd:personnelPwdTwo,pkPersonnelId:$("#userId").val()};
                var data=postAjax(url,dataJson);
                if (data.code === 1) {
                    layer.msg('修改成功',{
                        offset:['50%'],
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    },function(){
                        var url=getRootPath()+"OaPersonnelAction/logout";
                        var data=getAjaxById(url);
                        if(data==1){
                            window.location.href= getRootPath() + "pages/dkmoa/login.html";
                        }
                    });
                }  else {
                    layer.msg("修改失败");
                }
             return false;
         }
        });

        //重新渲染表单函数
        function renderForm() {
            layui.use('form', function () {
                var form = layui.form(); //高版本建议把括号去掉，有的低版本，需要加()
                form.render();
            });
        }

        form.render();


    });

</script>
</body>
</html>